package com.dz.config;

import com.dz.bean.guanli;
import com.dz.dao.guanliMapper;

import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;


import javax.annotation.Resource;
import java.util.List;


public class UserRealm extends AuthorizingRealm {
    @Resource
    private guanliMapper guanliMapper;

//    授权
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }
//认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {


        UsernamePasswordToken token1 = (UsernamePasswordToken) token;
        guanli g1=new guanli();
        g1.setAname(token1.getUsername());
        g1.setApsw(String.valueOf(token1.getPassword()));

        List<guanli> list = guanliMapper.login(g1);

        if(null == list || list.size() ==0)
        {
            return null;
        }


//        密码认证，shiro
        return new SimpleAuthenticationInfo("",token1.getPassword(),"");
    }
}
